package com.lap.permission.dto.response;

import com.lap.framework.entity.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NonNull;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

@Data
@Schema(description = "区域返回")
public class RegionDTO extends BaseEntity implements Comparable<RegionDTO>, Serializable {
    @Serial
    private static final long serialVersionUID = 5384571702141955703L;

    @Schema(description = "主键")
    private Integer id;

    @Schema(description = "父id")
    private Integer pid;

    @Schema(description = "父路径")
    private List<Integer> pidPaths;

    @Schema(description = "区域编码")
    private String code;

    @Schema(description = "区域名称")
    private String name;

    @Schema(description = "排序")
    private Integer orders;

    @Schema(description = "子集合")
    private List<RegionDTO> children;

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
    }

    @Override
    public boolean equals(Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj);
    }

    @Override
    public int compareTo(@NonNull RegionDTO o) {
        return this.orders.compareTo(o.getOrders());
    }

}
